﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TemplateFoundation.Configuration;

namespace TemplateFoundation.Tests.UnitTests.Configuration
{
    [TestClass]
    public class SiteSettingsStaticFiles
    {
        [TestMethod]
        [TestCategory("Site settings")]
        public void TestStaticFilePathDefaultsToTemplates()
        {
            Settings.Instance.StaticFilesPath = null;

            Assert.AreEqual("/Templates/",Settings.Instance.StaticFilesPath, "Static file path did not default to '/Templates/'");
        }

        [TestMethod]
        [TestCategory("Site settings")]
        public void TestStaticFilePathHasTrailingSlashEvenIfNotSpecified()
        {
            Settings.Instance.StaticFilesPath = "/Static/Folder";

            Assert.AreEqual("/Static/Folder/",Settings.Instance.StaticFilesPath, "Static file path did not have a trailing slash'");
        }

        [TestMethod]
        public void TestValidNonMinifiedMainStylesheetLinkWhenStaticFilePathIsSpecified()
        {
            Settings.Instance.StaticFilesPath = "/Static";

            Assert.AreEqual("/Static/css/main.css", Settings.Instance.GetMainStylesheetPath(false),"Invalid non-minified path with specified static file path");
        }

        [TestMethod]
        public void TestValidMinifiedMainStylesheetLinkWhenStaticFilePathIsSpecified()
        {
            Settings.Instance.StaticFilesPath = "/Static";

            Assert.AreEqual("/Static/css/main.min.css",Settings.Instance.GetMainStylesheetPath(true), "Invalid minified path with specified static file path");
        }

        [TestMethod]
        public void TestValidNonMinifiedMainStylesheetLinkWhenStaticFilePathIsNotSpecified()
        {
            Settings.Instance.StaticFilesPath = null;

            Assert.AreEqual("/Templates/css/main.css",Settings.Instance.GetMainStylesheetPath(false), "Invalid minified path with unspecified static file path");
        }

        [TestMethod]
        public void TestValidMinifiedMainStylesheetLinkWhenStaticFilePathIsNotSpecified()
        {
            Settings.Instance.StaticFilesPath = null;

            Assert.IsTrue(Settings.Instance.GetMainStylesheetPath(true) == "/Templates/css/main.min.css", "Invalid minified path with unspecified static file path");
        }

        [TestMethod]
        public void TestValidMinifiedStylesheetLinkWhenFilenameHasExtensionAndStaticFilePathIsNotSpecified()
        {
            Settings.Instance.StaticFilesPath = null;

            Assert.AreEqual("/Templates/css/mystylesheet.min.css",Settings.Instance.GetStylesheetPath("mystylesheet.css",true), "Invalid minified path with file extension and unspecified static file path");
        }

        [TestMethod]
        public void TestValidMinifiedStylesheetLinkWhenFilenameHasExtensionAndStaticFilePathIsSpecified()
        {
            Settings.Instance.StaticFilesPath = "/Static/";

            Assert.AreEqual("/Static/css/mystylesheet.min.css", Settings.Instance.GetStylesheetPath("mystylesheet.css", true), "Invalid minified path with file extension and unspecified static file path");
        }

        [TestMethod]
        public void TestValidMinifiedStylesheetLinkWhenFilenameHasExtensionAndStaticFilePathHasNoLeadingSlash()
        {
            Settings.Instance.StaticFilesPath = "Static/";

            Assert.AreEqual("/Static/css/mystylesheet.min.css",Settings.Instance.GetStylesheetPath("mystylesheet.css", true), "Invalid minified path when static file path lacks leading slash");
        }

        [TestMethod]
        public void TestValidMinifiedStylesheetLinkWhenFilenameHasNoExtensionAndStaticFilePathIsNotSpecified()
        {
            Settings.Instance.StaticFilesPath = null;

            Assert.AreEqual("/Templates/css/mystylesheet.min.css",Settings.Instance.GetStylesheetPath("mystylesheet", true), "Invalid minified path with file extension and unspecified static file path");
        }

        [TestMethod]
        public void TestValidMinifiedStylesheetLinkWhenFilenameHasNoExtensionAndStaticFilePathIsSpecified()
        {
            Settings.Instance.StaticFilesPath = "/Static/";

            Assert.AreEqual("/Static/css/mystylesheet.min.css", Settings.Instance.GetStylesheetPath("mystylesheet", true), "Invalid minified path with file extension and unspecified static file path");
        }
    }
}
